package com.financial.sys.controller.repayment;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.financial.sys.service.repayment.TRepaymentService;
import com.financial.sys.vo.repayment.TRepaymentQuery;
import com.financial.sys.vo.repayment.TRepaymentrepayQuery;
import com.financial.common.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hzy
 * @since 2020-02-12
 */

/**
 * 还款
 */
@RestController
@RequestMapping("/finance/repayment")
public class TRepaymentController {
    //  http://localhost:8080/finance/repayment/query
    @Autowired
    private TRepaymentService TRepaymentService;

    @PostMapping(value = "/query")
    public JsonResult query(TRepaymentQuery TRepaymentQuery) {
        JsonResult jsonResult = new JsonResult();
        try {
            IPage page = TRepaymentService.query(TRepaymentQuery);
            PageResult pageResult = new PageResult(page.getRecords(), (int) page.getPages(), (int) page.getCurrent(), (int) page.getSize());
            jsonResult.setCode(ResponseCode.SUCCESS);
            jsonResult.setData(pageResult);
        } catch (Exception e) {
            jsonResult.setCode(ResponseCode.ERROR);
            jsonResult.setMsg("查询不到还款数据");
            e.printStackTrace();
        }
        return jsonResult;
    }

    @PostMapping("/repay")
    public JsonResult repay(TRepaymentrepayQuery TRepaymentrepayQuery){
        JsonResult jsonResult = new JsonResult();
        JsonResult repay = TRepaymentService.repay(TRepaymentrepayQuery);
        jsonResult.setData(repay);
        return jsonResult;
    }

}

